/***** SliderPresenter.m -- Slider data display object implementation
	NeXTstep Measurement Kit
	by Alex Meyer <ameyer@phoenix.Princeton.EDU>
	for computer science senior thesis
	19 April 1992 -- created
	22 April 1992 -- incorporated structs.h & added identify
*****/

#import <stdlib.h>
#import <stdio.h>
#import <string.h>
#import <appkit/Application.h>
#import "Historian.h"
#import "SliderPresenter.h"

@implementation SliderPresenter

static id instance = nil;

+ new
{
	if (instance == nil) {
		instance = [self alloc];
		[NXApp loadNibSection:"SliderPresenter.nib"
			owner:instance];
	}
	return (instance);
}


- showData:sender
{
	int i,tag;
	float x,y,width,height;
	char *p,*text;
	NXAtom key;

	[sender copyDataTo:&rec];
	key = [sender getKey];
	for (p = key,i = 0;*p != '|';++p)
		++i;
	text = malloc(i + 1);
	strncpy(text,key,i);
	text[i] = 0;
	sscanf(p,"|%d|%f|%f|%f|%f",&tag,&x,&y,&width,&height);
	[form setStringValue:text
		at:0];
	[form setIntValue:tag
		at:1];
	[form setFloatValue:x
		at:2];
	[form setFloatValue:y
		at:3];
	[form setFloatValue:width
		at:4];
	[form setFloatValue:height
		at:5];
	[form setIntValue:rec.numHits
		at:6];			/* should be unsigned */
	[form setDoubleValue:rec.timeIn
		at:7];
	[form setDoubleValue:rec.timeBetween
		at:8];
	[histView copyInNum:SLIDERHIST
		data:rec.histogram];
	[histView display];
	free(text);
	[window orderFront:self];
	return self;
}


- hide:sender
{
	[window orderOut:self];
	return self;
}


- (NXAtom)identify
{
	return (NXUniqueString("Sliders"));
}

@end
